FROM openjdk:8-jdk

# 设置环境变量
ENV HADOOP_VERSION 3.3.6
ENV HADOOP_HOME /usr/local/hadoop
ENV PATH $PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
ENV HDFS_NAMENODE_USER=root
ENV HDFS_DATANODE_USER=root
ENV HDFS_SECONDARYNAMENODE_USER=root

# 下载并解压Hadoop, 若下载太慢可手动下载上传再copy
#RUN curl -fSL "https://dlcdn.apache.org/hadoop/common/hadoop-$HADOOP_VERSION/hadoop-$HADOOP_VERSION.tar.gz" -o /tmp/hadoop.tar.gz
COPY hadoop-$HADOOP_VERSION.tar.gz /tmp/hadoop.tar.gz

RUN tar -xvf /tmp/hadoop.tar.gz -C /usr/local/ \
    && ln -s /usr/local/hadoop-$HADOOP_VERSION/ /usr/local/hadoop \
    && rm /tmp/hadoop.tar.gz

# 设置权限
RUN chmod +x $HADOOP_HOME/bin/hadoop
# 配置Hadoop
COPY conf/hadoop-env.sh /usr/local/hadoop/etc/hadoop/hadoop-env.sh
COPY conf/core-site.xml /usr/local/hadoop/etc/hadoop/core-site.xml
COPY conf/hdfs-site.xml /usr/local/hadoop/etc/hadoop/hdfs-site.xml
COPY conf/mapred-site.xml /usr/local/hadoop/etc/hadoop/mapred-site.xml
COPY conf/yarn-site.xml /usr/local/hadoop/etc/hadoop/yarn-site.xml

# 设置工作目录
WORKDIR $HADOOP_HOME

# 暴露端口
EXPOSE 9870 8088